package com.ruoyi.team.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.team.mapper.CustomerLinkmaneMapper;
import com.ruoyi.team.domain.CustomerLinkmane;
import com.ruoyi.team.service.ICustomerLinkmaneService;

/**
 * 客户联系人Service业务层处理
 *
 * @author sjl
 * @date 2022-11-27
 */
@Service
public class CustomerLinkmaneServiceImpl extends ServiceImpl<CustomerLinkmaneMapper, CustomerLinkmane> implements ICustomerLinkmaneService {
    @Autowired
    private ISysUserService userService;

    /**
     * 查询客户联系人列表
     *
     * @param customerLinkmane 客户联系人
     * @return 客户联系人
     */
    @Override
    public List<CustomerLinkmane> selectCustomerLinkmaneList(CustomerLinkmane customerLinkmane) {
        List<CustomerLinkmane> customerLinkmanes = getBaseMapper().selectCustomerLinkmaneList(customerLinkmane);
        for (CustomerLinkmane linkmane : customerLinkmanes) {
            SysUser sysUser = userService.selectUserById(linkmane.getInputUser());
            linkmane.setInputUserName(sysUser.getNickName());
        }
        return customerLinkmanes;
    }

    @Override
    public boolean save(CustomerLinkmane customerLinkmane) {
        LoginUser user = SecurityUtils.getLoginUser();
        customerLinkmane.setInputUser(user.getUserId());
        customerLinkmane.setInputTime(new Date());
        return super.save(customerLinkmane);
    }
}